<?php
require_once "stemmer.php";

function tags_main($db, &$view, $translate) {
	global $config;
	if (empty($_GET['term']) || $_GET['term'] == '[Uncategorized]')
		$queryTerm = "IS NULL";
	else
		$queryTerm = "LIKE " . $db->quote('%' . PorterStemmer::Stem($_GET['term']) . '%');
	$data = $db->fetchAll("(SELECT 'news' as type, id, title, pubdate FROM news WHERE published = 1 AND tags $queryTerm) UNION
						   (SELECT 'reader' as type, id, title, FROM_UNIXTIME(timestamp) as pubdate FROM reader WHERE tags $queryTerm) UNION
						   (SELECT 'article' as type, id, title, pubdate from articles WHERE published = 1 AND tags $queryTerm) ORDER BY pubdate DESC");
	$view->assign('data', $data);
	$view->display('tags.tpl');
}
?>
